package com.share.iostream;

import java.io.*;

public class TestObjectIO {
	public static void main(String args[]) throws Exception {
		T t = new T();
		t.k = 8;//修改了T中的k值
		
		FileOutputStream fos = new FileOutputStream(
				"E:\\Coursera-Java\\Eclipse\\workspace\\chapter18-IO\\src\\com\\share\\iostream\\testobjection.dat");

		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(t);
		oos.flush();
		oos.close();

		FileInputStream fis = new FileInputStream(
				"E:\\Coursera-Java\\Eclipse\\workspace\\chapter18-IO\\src\\com\\share\\iostream\\testobjection.dat");
		
		ObjectInputStream ois = new ObjectInputStream(fis);
		
		T tReaded = (T) ois.readObject();
		
		System.out.println(tReaded.i + " " + tReaded.j + " " + tReaded.d + " " + tReaded.k);

	}
}

class T implements Serializable //可以被序列化的。标记性接口，实现了接口，里面没方法。。
{
	int i = 10;
	int j = 9;
	double d = 2.5;
	int k = 15;

	// transient透明的 比如transient int k=15;
}